package com.codenjoy.calculator;

public class Calculator {

    public String calculate(String expr, String bs) {
        Parser parser = null;
        if (bs.equalsIgnoreCase("rome")) {
            parser = new RomeParser();
        }
        else {
            parser = new BaseParcer(bs);
        }

        parser.validate(expr);

        int pos  = expr.indexOf('+');

        String part1 = expr.substring(0, pos);
        String part2 = expr.substring(pos + 1, expr.length());

        long sum = parser.decode( part1);
        long sum2 = parser.decode( part2);

        long result = sum + sum2;

        return parser.encode( result);
    }

}
